﻿using Microsoft.SharePoint.Administration;
using SPSDeploy.Extensions.Controllers;
using System.Xml.Linq;

namespace SPSDeploy.Extensions.Modules.Compare
{
    /// <summary>
    /// Farm compare module
    /// </summary>
    internal class FarmModule : BaseModule
    {

        /// <summary>
        /// Initialization
        /// </summary>
        /// <param name="controller"></param>
        internal FarmModule(BaseController controller)
            : base(controller)
        {
        }

        /// <summary>
        /// Execute module
        /// </summary>
        /// <param name="compare"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        internal override XElement Execute(XElement compare, XElement parent)
        {
            SPFarm farm = SPFarm.Local;
            XElement result = new XElement("farm");
            XElement updates = GetUpdatesElement();
            Compare(updates, compare.Attribute("configuration"), farm.Name);
            Compare(updates, compare.Attribute("version"), farm.BuildVersion.ToString());
            Tools.RollupElement(result, updates);
            controller.OnProgressMessage("Farm information compared.");
            return result;
        }

    }
}